// -*- c++ -*-
#ifndef RANDOM_H
#define RANDOM_H

#include <ctime>

extern "C" {
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
}


class Random {
public:

  static Random defaultRandom() { return random; }

  Random() {
    rng = gsl_rng_alloc(gsl_rng_mt19937);
    gsl_rng_set(rng, time(0));
  }

  Random(unsigned long seed) {
    rng = gsl_rng_alloc(gsl_rng_mt19937);
    gsl_rng_set(rng, seed);
  }

  ~Random() {
    gsl_rng_free(rng);
  }

  double uniform() {
    return gsl_rng_uniform(rng);
  }

  double stdnorm() {
    return gsl_ran_ugaussian(rng);
  }

  double chisqr(int d) {
    return gsl_ran_chisq(rng, d);
  }

private:

  static Random random;
  
  gsl_rng* rng;
};

#endif
